package io.netty.myExample.zhanglong.p8类聊天室;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.util.Scanner;

/**
 * @Author : duyutian
 * @Date : 2019/11/20 20:13
 * @Version 1.0
 */
public class ChatClient {
    public static void main(String[] args) throws Exception {
        NioEventLoopGroup eventGroup = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(eventGroup)
                    .channel(NioSocketChannel.class)
                    .handler(new io.netty.myExample.zhanglongp8类聊天室.ChatClientInitializer());
            Channel channel = bootstrap.connect("localhost", 8090)
                    .sync().channel();
            // channel.closeFuture().sync();
            /**
             * 接受键盘指令
             */
            //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            Scanner scanner = new Scanner(System.in);
            for (; ; ) {
                // channel.writeAndFlush(br.readLine() + "\r\n");
                String s = scanner.next();
                channel.writeAndFlush(s+"\r\n");
            }

        } finally {
            eventGroup.shutdownGracefully();
        }


    }
}
